<template>
    <div>
        <jgsearch
            :searchData="searchData"
            @on-input="searchaskData"
            @on-change-change="changeaskData"
            @on-change-Radio="changeRadio"
            @on-change-Checkbox="changeCheckbox"
            @on-change-Date="changeDate"
        >
        </jgsearch>
        <jgtable
            :data="list"
            :params="params"
            :columns="columns"
            :loading="loading"
            :total="total"
            @askData="askData"></jgtable>
    </div>
</template>

<script>
import jgsearch from '../components/search'
import jgtable from '../components/table'
import mixin from "../components/mixin";
import {
    wechatusercluelist,
    wechatuserclueinfo,
    clueusercontact,
    concatWxPatient,
    wechatmessagelist,
    getOldPatient,
    patientindexsearchcity,
    patientindexsearchmobile,
} from "@api/hqapi";
export default {
    name: 'wechat', // 微信
    mixins: [mixin],
    components: { jgsearch, jgtable },
    props: {
        booltimeButton: { type: Boolean, default: true },
        clue_status_id: { type: [String, Number], default: '' },
        ceshiButton: { type: Boolean, default: false },
        columnsHeader: { type: [String, Number], default: 0 },
        customer: { type: Boolean, default: false },
    },

    data() {
        const options = { disabledDate(date) { return date && date.valueOf() > Date.now() }}
        return {
            searchData: {
                left: [
                    { id: 0, key: "Input", placeholder: "请输入微信号/昵称", clearable: true, style: { width: "160px" }, value: "" },
                    { id: 18, key: "Select", placeholder: "添加方式", clearable: true, style: { width: "100px" }, value: "", childList: [], callback: "change" },
                    { id: 19, key: "Select", placeholder: "部门", clearable: true, style: { width: "100px" }, value: "", childList: [], callback: "change" },
                    { id: 20, key: "Select", placeholder: "客服微信号", clearable: true, style: { width: "180px" }, value: "", childList: [], callback: "change" },
                    { id: 21, key: "Select", placeholder: "联系人员", clearable: true, style: { width: "100px" }, value: "", childList: [], callback: "change" },
                    { id: 0, key: "DatePicker", type: "daterange", options: options, placeholder: "请选择来电日期", value: [new Date(),new Date()], callback: "Date" },
                    { id: 0, key: "RadioGroup", show: { show: true }, type:'button', value: 10, childList: [{ label: '近10天', value: 10 },{ label: '近30天', value: 30 },{ label: '近90天', value: 90 }], callback: "Radio"},
                    { id: 0, key: "CheckboxGroup", value: [], childList: [{ label: '重复', value: 1 },{ label: '手机号', value: 2 },{ label: '测试', value: 3, show: true }], callback: "Checkbox" }
                ],
            },
            columns: [
                { title: "微信信息", slot: "wechatwechat", width: 280, fixed: "left" },
                { title: "微信备注", key: "remark", minWidth: 168 },
                { title: "微信标签", slot: "wechattags", minWidth: 150 },
                { title: "最近沟通时间", key: "last_communication_time", width: 180 },
                { title: "客服微信号", key: "wechatno", minWidth: 180, ellipsis: true, tooltip: true },
                { title: "添加方式", slot: "wechatsource_type", minWidth: 120, ellipsis: true, tooltip: true },
                { title: "归属部门", key: "department_name", width: 118 },
                { title: "联系人员", key: "operation_name", minWidth: 120, ellipsis: true, tooltip: true },
                { title: "添加时间", key: "created_at", width: 180 },
                { title: "操作", fixed: "right", slot: "wechatoperation", width: 80 },
            ],
            params: {
                page: 1,
                pageSize: 10,
                keyword: "",
                department_id: "",
                clue_status: "",
                wechatno: "",
                source_type: "",
                have_repeat: 0,
                operation_id: "",
                start_time: new Date(),
                end_time: new Date(),
            }, //  请求参数
        };
    },
    mounted() {
        wechatusercluelist({page: 1,pageSize: 1}).then(res => {
            this.device = res.wechatno
            this.searchData.left.forEach(item => {
                if (item.id === 18) {
                    item.childList = res.source_type;
                } else if (item.id === 19) {
                    item.childList = res.department
                } else if (item.id === 21) {
                    item.childList = res.operation_member
                }
            });
        })
    },
    methods: {
        initial() {
            this.initials()
        },
        askData() {
            this.loading = true
            this.getparams()
            wechatusercluelist(this.params).then((res) => {
                this.list = Object.freeze(res.list.list);
                this.total = res.list.total;
                let params = { key: 'wechat', total: res.list.total }
                this.$emit('returntotal', params);
                this.loading = false
            });
        },
    },
};
</script>

<style lang="scss" scoped>

</style>